package com.imooc.sell.dataobject;

import com.imooc.sell.VO.pan.RemarkRequest;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 评论实体类
 */
@Entity
@Data
@DynamicUpdate
@Proxy(lazy = false)
public class Remark {
    /**
     * 评论id
     */
    @Id
    @GeneratedValue(generator = "myGenerator")
    @GenericGenerator(name = "myGenerator", strategy = "com.imooc.sell.utils.MyGenerator")
    private String remarkId;
    /**
     * 发表评论的订单号
     */
    private String orderId;
    /**
     * 评论内容
     */
    private String comment;
    /**
     * 评论人昵称
     */
    private String nickName;
    /**
     * 评论人头像
     */
    private String headImg;
    /**
     * 评论时间
     */
    private Date createTime;
    /**
     * 更新时间
     */
    private Date updateTime;

    public Remark() {

    }

    public Remark(RemarkRequest remarkRequest) {
        this.setRemarkId(remarkRequest.getRemarkId());
        this.setOrderId(remarkRequest.getOrderId());
        this.setNickName(remarkRequest.getNickName());
        this.setComment(remarkRequest.getComment());
        this.setHeadImg(remarkRequest.getHeadImg());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ParsePosition pos1 = new ParsePosition(0);
        ParsePosition pos2 = new ParsePosition(0);
        Date createtime = sdf.parse(remarkRequest.getCreateTime(), pos1);
        /* Date updatetime = sdf.parse(remarkRequest.getUpdateTime(),pos2);*/
        this.setCreateTime(createtime);
        /*this.setUpdateTime(updatetime);*/
    }
}
